package com.shopoo.behavior.mobile;

import com.shopoo.behavior.api.ShareService;
import com.shopoo.behavior.dto.clientobject.BehaviorShareCO;
import com.shopoo.behavior.dto.cqe.BehaviorShareAddCmd;
import com.szmengran.cola.dto.MultiResponse;
import com.szmengran.cola.dto.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * File Name:ShareController.java Package Name:com.szmengran.behavior.controller
 * 
 * @TODO:
 * @author <a href="mailto:android_li@sina.cn">LiMaoYuan</a> Copyright (c) 2019,
 *         深圳市梦燃科技有限公司 All Rights Reserved.
 * @createTime 2019年6月3日下午5:18:31
 */
@Tag(name = "用户分享API")
@RestController
@RequestMapping(path = "/share", produces = { "application/json" })
public class ShareController {

    @Autowired
    private ShareService shareService;

    @Operation(summary = "保存分享信息")
    @PostMapping
    public Response insert(@RequestBody BehaviorShareAddCmd behaviorShareAddCmd) {
        return shareService.insert(behaviorShareAddCmd);
    }

    @Operation(summary = "增加阅读量")
    @PutMapping("/read/{promotionid}/{userid}")
    public Response addRead(@PathVariable("promotionid") String promotionid, @PathVariable("userid") String userid)
            {
        return shareService.addRead(promotionid, userid);
    }

    @Operation(summary = "点赞")
    @PutMapping("/like/{promotionid}/{userid}")
    public Response addLike(@PathVariable("promotionid") String promotionid, @PathVariable("userid") String userid)
            {
        return shareService.addLike(promotionid, userid);
    }

    @Operation(summary = "取消点赞")
    @DeleteMapping("/like/{promotionid}/{userid}")
    public Response cancelLike(@PathVariable("promotionid") String promotionid, @PathVariable("userid") String userid)
            {
        return shareService.cancelLike(promotionid, userid);
    }

    @Operation(summary = "查找传单信息")
    @GetMapping("/{promotionid}")
    public MultiResponse<BehaviorShareCO> findByPromotionid(@PathVariable("promotionid") String promotionid) {
        return shareService.findByPromotionid(promotionid);
    }
}
